#ifndef MLTOOL_OPERATIONS_P_H
#define MLTOOL_OPERATIONS_P_H

#include<thread>
#include"tags.h"
#include<algorithm>
#include<vector>

template<class InputIt, class UnaryFunction>
void for_each_p(InputIt first, InputIt last, UnaryFunction f, size_t np)
{
	size_t N = last - first;
	auto beg = first;
	auto end = last;
	std::vector<std::thread> t(np);
	if(np)
	{
		for(size_t i = 0; i < np; ++i)
		{
			t[i] = std::thread(std::for_each<InputIt, InputIt, UnaryFunction>, beg, end, f);
			beg = end;
		}
	}
	std::for_each(beg, last, f);
	for(size_t i = 0; i < np; ++i)
		t[i].join();

}

#endif
